package org.swxjava.util;

import java.lang.reflect.Array;

public class ArrayUtils {

	public static int getLength(Object array) {
		if (array == null) {
			return 0;
		}
		return Array.getLength(array);
	}

	public static void reverse(Object[] array) {
		if (array == null) {
			return;
		}
		int i = 0;
		int j = array.length - 1;
		Object tmp;
		while (j > i) {
			tmp = array[j];
			array[j] = array[i];
			array[i] = tmp;
			j--;
			i++;
		}
	}

	public static void reverse(byte[] array) {
		if (array == null) {
			return;
		}
		int i = 0;
		int j = array.length - 1;
		byte tmp;
		while (j > i) {
			tmp = array[j];
			array[j] = array[i];
			array[i] = tmp;
			j--;
			i++;
		}
	}

	public static String toString(Object[] array) {
		if (array == null) {
			return "";
		} else {
			StringBuffer buf = new StringBuffer("[");
			for (int i = 0; i < array.length; i++) {
				if (i != 0) {
					buf.append(",");
				}
				buf.append(array[i]);
			}
			return buf.append("]").toString();
		}
	}
}
